package com.example.pc.greenplants.First;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.pc.greenplants.Banner.CustomBanner;
import com.example.pc.greenplants.Community.Shequ_dl;
import com.example.pc.greenplants.Personal.Personal;
import com.example.pc.greenplants.Plant;
import com.example.pc.greenplants.PlantAdapter;
import com.example.pc.greenplants.R;

import java.util.ArrayList;
import java.util.List;

import cn.bmob.v3.Bmob;
import cn.bmob.v3.BmobUser;


public class Main2Activity extends AppCompatActivity {

    private CustomBanner<String> mBanner;
    private List<Plant> plantList = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        TextView textView = findViewById(R.id.userfor);
        textView.setText(BmobUser.getCurrentUser().getUsername() + ",欢迎你");
        Button btn2 = (Button) findViewById(R.id.button2);
        btn2.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                Intent intent = new Intent(Main2Activity.this, Shequ_dl.class);
                startActivity(intent);
            }
        });
        Button btn3 = (Button) findViewById(R.id.button3);
        btn3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(Main2Activity.this, Personal.class);
                startActivityForResult(intent, 1);
            }
        });
        Bmob.initialize(this, "fa96b598aa0534b09043ff71c1b27ace");




        //隐藏标题栏
        ActionBar actionBar = getSupportActionBar();
        if (actionBar!=null){
            actionBar.hide();
        }
        initPlants();
        RecyclerView recyclerView= findViewById(R.id.recycler_view);
        StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(2,StaggeredGridLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(layoutManager);
        PlantAdapter adapter = new PlantAdapter(plantList);
        recyclerView.setAdapter(adapter);



        mBanner = findViewById(R.id.banner);
        ArrayList<Integer> images = new ArrayList<>();
        images.add(R.mipmap.img1);
        images.add(R.mipmap.img2);
        images.add(R.mipmap.imag3);
        images.add(R.mipmap.img4);
        images.add(R.mipmap.img5);
        setBean(images);
    }
    private void setBean(final ArrayList<Integer> beans) {
        mBanner.setPages(new CustomBanner.ViewCreator<String>() {
            @Override
            public View createView(Context context, int position) {
                ImageView imageView = new ImageView(context);
                imageView.setScaleType(ImageView.ScaleType.FIT_XY);
                return imageView;
            }

            @Override
            public void updateUI(Context context, View view, int position, Integer s) {
                //Glide 加载图片简单用法
                Glide.with(context).load(s).into((ImageView) view);
            }
        }, beans).startTurning(5000);
    }








    private void initPlants() {
        for(int i=0;i<1;i++){
            Plant dingxiangqiu = new Plant("丁香秋",R.drawable.dingxiangqiu);
            plantList.add(dingxiangqiu);

            Plant guibeizhu = new Plant("龟背竹",R.drawable.guibeizhu);
            plantList.add(guibeizhu);

            Plant lanpenhua = new Plant("蓝盆花",R.drawable.lanpenhua);
            plantList.add(lanpenhua);

            Plant qingyebiyu = new Plant("青叶碧玉",R.drawable.qingyebiyu);
            plantList.add(qingyebiyu);

            Plant siyecao = new Plant("四叶草",R.drawable.siyecao);
            plantList.add(siyecao);

            Plant xiaxuepianlian = new Plant("夏雪片莲",R.drawable.xiaxuepianlian);
            plantList.add(xiaxuepianlian);

            Plant yulu = new Plant("玉露",R.drawable.yulu);
            plantList.add(yulu);

            Plant baizhang = new Plant("白鹤芋",R.drawable.baizhang);
            plantList.add(baizhang);

            Plant shengshihua = new Plant("生石花",R.drawable.shengshihua);
            plantList.add(shengshihua);

            Plant diaolan = new Plant("吊兰",R.drawable.diaolan);
            plantList.add(diaolan);
        }
    }


}
